#!/usr/bin/python3
# -*- coding:utf-8 -*-
""""
@Author: 李吉凯
@Email: lijk34925@hundsun.com
@Time: 2022/5/11 10:42
@File: killDriver.py
"""
import os
import platform

from BladeFerm.Lib.Common import logger

class KillChromedriver():
    def __init__(self):
        self.isCentos = False  # 当前环境时候是linux下
        self.__judge_cur_system()


    def __judge_cur_system(self):
        logger.info('当前系统: ' + platform.system())
        if platform.system() == 'Windows':
            self.isCentos = False
        elif platform.system() == 'Linux':
            self.isCentos = True
        else:
            logger.info('其他系统：' + platform.system())

    def kill_chromedriver(self):
        if self.isCentos:
            cmd = '''ps -ef | grep chromedriver | grep -v grep | awk '{print "kill -9" $2}'| sh'''
        else:
            cmd = '''taskkill /F /im chromedriver.exe'''
        os.system(cmd)
        logger.info(f'act cmd: {cmd}')
        return True


if __name__ == '__main__':
    kill_chromedriver = KillChromedriver()
    kill_chromedriver.kill_chromedriver()
